package kr.hkit.powerjava.chapter14;

import java.awt.Component;
import java.awt.HeadlessException;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class BoxTest extends JFrame{

	public BoxTest() throws HeadlessException {
		setTitle("BoxLayoutTest");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel panel = new JPanel();
		
		panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
		
		makeButton(panel, "Button1");
		makeButton(panel, "Button2");
		makeButton(panel, "Button3");
		makeButton(panel, "B4");
		makeButton(panel, "Button5");
		
		add(panel);
		pack();
		setVisible(true);
	}

	private void makeButton(JPanel panel, String string) {
		JButton button = new JButton(string);
		button.setAlignmentX(Component.CENTER_ALIGNMENT);
		panel.add(button);
	}

	public static void main(String[] args) {
		BoxTest box = new BoxTest();
	}
	
}
